package cn.edu.scau.cmi.liangzijian.ioc.spring;

import java.net.URL;
import java.util.ResourceBundle;

import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.liangzijian.ioc.spring.entity.Student;
import cn.edu.scau.cmi.liangzijian.ioc.spring.entity.Teacher;
import cn.edu.scau.cmi.liangzijian.ioc.spring.util.ApplicationContextUtil;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;


public class UIController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private TextArea board;

    private ApplicationContext applicationContext = getApplicationContext();
    
    @FXML
    void accessStudent(MouseEvent event) {
    	Student student = (Student)applicationContext.getBean("zhangsan");
    	Teacher teacher = (Teacher)applicationContext.getBean("liang");
    	board.appendText(student.toString()+"\n");
    	board.appendText(student.getName() + "的毕业设计指导导师是：" + teacher.getName()+"\n\n");
    }

    @FXML
    void accessTeacher(MouseEvent event) {
    	Teacher teacher = (Teacher)applicationContext.getBean("liang");
    	board.appendText(teacher.toString()+"\n");
    	board.appendText("该teacher的名字是：" + teacher.getName()+"\n\n");
    }

    @FXML
    void initialize() {
        assert board != null : "fx:id=\"board\" was not injected: check your FXML file 'UI.fxml'.";
    }

    private static ApplicationContext getApplicationContext() {
    	return ApplicationContextUtil.getInstance();
    }
    
}
